import { ISkillBase } from "../../../ADCore/Interfaces/ISkill";
import { RoleAction } from "../../../ADCore/Interfaces/IEnum";
import { StateMachine } from "../../../ADCore/Implements/ImpStateMachine/StateMachine";

export default class RoleSkillState extends StateMachine {
  protected _skill: ISkillBase;

  public onEnter(obj: any = null): void {
    this._skill = obj as ISkillBase;
    if (this._skill == null) {
      console.debug("攻击状态 技能参数为null");
      this.owner.changeState(RoleAction.idle);
    }
    this._skill.release();
  }

  public onUpdate(): void {
    super.onUpdate();
    if (this._skill) {
      this._skill.update();
    }
  }

  public onLeave(newState: RoleAction): void {
    if (this._skill) {
      this._skill.stop();
      this._skill = null;
    }
  }

  public getStateKey(): RoleAction {
    return RoleAction.skill;
  }
}
